#第一题、用for循环和while来完成简单的计数
#for循环
l = [1, 2, 3, 4]
for e in l:
    print(e)
print(f"final e value: {e}\n")

#while循环
counter = 0

while counter < 10:
    if counter == 10:
        break
    print(f"sim statement: {counter}")
    counter += 1


#第二题、用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内
#for循环
a = 0
b = 1
sum = 0
for sum in range(0, 12):
    if sum < 2:
        print(sum)
    else:
        sum = a + b;
        a = b;
        b = sum;
        print(sum)

#while循环
a_1 = 0
b_1 = 1
sum_1 = 0
while sum_1 < 80:
    if sum_1 < 2:
        print(sum_1)
        sum_1 += 1;
    elif sum_1 < 80:
        sum_1 = a_1 + b_1;
        a_1 = b_1;
        b_1 = sum_1;
        if sum_1 >= 2:
            print(sum_1)
    elif sum_1 > 80:
        break
#第三题、在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError
def add(a, b):
    return a + b


def sub(a, b):
    return a - b


def mul(a, b):
    return a * b


def div(a, b):
    try:
        return a / b
    except ZeroDivisionError:
        raise ParamsError

a = 2
b = 0


print("a+b=", add(a, b))
print("a-b=", sub(a, b))
print("a*b=", mul(a, b))
print("a/b=", div(a, b))

